import { defineStore } from "pinia";

export const useRankStore = defineStore("useRankStore", {
  state: () => {
    return {
      // 荣誉
      honor: {
        // 荣誉锁
        rewardsLocked: false,
        // 荣誉等级
        honorLevel: 0,
        // 荣誉点数
        checkpoint: 0,
      },
      // 段位
      rank: {
        // 单双
        rankSolo: {
          // 段位
          tier: "",
          // 那个段位
          division: "",
          // 段位点数
          leaguePoints: 0,
          // 胜利次数
          wins: 0,
          // 失败次数
          losses: 0,
        },
        // 灵活
        rankSr: {
          // 段位 或 未定级
          tier: "",
          // 那个段位
          division: "",
          // 段位点数
          leaguePoints: 0,
          // 胜利次数
          wins: 0,
          // 失败次数
          losses: 0,
        },
        // 云顶
        rankTft: {
          // 段位
          tier: "",
          // 那个段位
          division: "",
          // 段位点数
          leaguePoints: 0,
          // 胜利次数
          wins: 0,
          // 失败次数
          losses: 0,
        },
      },
    };
  },

  getters: {
    // 单双段位 黄金4 22
    rankSoloData(state) {
      let rankSolo = state.rank.rankSolo;

      // 段位
      let tier;
      if (rankSolo.tier === "未定级") {
        tier = "未定级";
      } else {
        tier = `${rankSolo.tier}${rankSolo.division} ${rankSolo.leaguePoints}`;
      }

      // 胜率
      let winRate = 1;

      winRate = rankSolo.wins / (rankSolo.wins + rankSolo.losses);
      winRate = Number(winRate.toFixed(3)) * 100;

      // 进行过游戏
      let isRun = true;
      if (rankSolo.wins === 0 && rankSolo.losses === 0) {
        isRun = false;
      }

      return {
        tier,
        winRate,
        isRun,
      };
    },

    // 灵活
    rankSrDate(state) {
      let rankSr = state.rank.rankSr;

      // 段位
      let tier;
      if (rankSr.tier === "未定级") {
        tier = "未定级";
      } else {
        tier = `${rankSr.tier}${rankSr.division} ${rankSr.leaguePoints}`;
      }

      // 胜率
      let winRate = 1;

      winRate = rankSr.wins / (rankSr.wins + rankSr.losses);
      winRate = Number(winRate.toFixed(3)) * 100;

      // 进行过游戏
      let isRun = true;
      if (rankSr.wins === 0 && rankSr.losses === 0) {
        isRun = false;
      }

      return {
        tier,
        winRate,
        isRun,
      };
    },

    // 云顶
    rankTftDate(state) {
      let { rankTft } = state.rank;
      // 段位
      let tier;
      if (rankTft.tier === "未定级") {
        tier = "未定级";
      } else {
        tier = `${rankTft.tier}${rankTft.division} ${rankTft.leaguePoints}`;
      }

      // 胜率
      let winRate = 1;

      winRate = rankTft.wins / (rankTft.wins + rankTft.losses);
      winRate = Number(winRate.toFixed(3)) * 100;

      // 进行过游戏
      let isRun = true;
      if (rankTft.wins === 0 && rankTft.losses === 0) {
        isRun = false;
      }

      return {
        tier,
        winRate,
        isRun,
      };
    },
  },
});
